package sns.action;

import org.springframework.transaction.annotation.Transactional;

import sns.bean.Impression;
import sns.bean.Relation;
import sns.bean.User;
import sns.dao.ImpressionDao;
import sns.dao.UserDao;
import sns.service.RelationService;
import sns.service.UserService;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class AddImpressionAction extends ActionSupport {
	// injection
	private ImpressionDao impressionDao;
	private UserDao userDao;
	private UserService userService;
	private RelationService relationService;
	// pass in
	private Long visitId;
	private String impressionContent;

	// return
	// private Long visitId;

	@Transactional
	public String execute() {

		if (visitId == null) {
			System.out.println("No visit id.");
			return ActionSupport.INPUT;
		}
		User currentUser = userService.getCurrentUser();
		User visitingUser = userDao.findUserById(visitId);
		Relation relation = relationService.getRelation(currentUser,
				visitingUser);
		Impression impression = new Impression();
		impression.setImpression(impressionContent);
		impression.setRelation(relation);

		impressionDao.save(impression);
		return ActionSupport.SUCCESS;
	}

	public Long getVisitId() {
		return visitId;
	}

	public void setVisitId(Long visitId) {
		this.visitId = visitId;
	}

	public void setImpressionDao(ImpressionDao impressionDao) {
		this.impressionDao = impressionDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public void setRelationService(RelationService relationService) {
		this.relationService = relationService;
	}

	public void setImpressionContent(String impressionContent) {
		this.impressionContent = impressionContent;
	}

}
